<?php

namespace App\Http\Controllers\Api;

use App\Models\TagsModel;
use App\Requests\AvatarRequest;
use App\Requests\EditPasswordRequest;
use App\Requests\EditUserInfoRequest;
use App\Requests\LoveInfoRequest;
use App\Requests\UserFavorRequest;
use App\Requests\UserForgetLoginPasswordRequest;
use App\Services\IndexService;
use App\Services\UserService;
use Carbon\Carbon;
use Framework\BaseController;
use Framework\Hope;
use Illuminate\Http\Request;


class UserController extends BaseController
{


    /**
     * 注销账户记录
     * @param UserService $service
     * @return void
     * @throws \Throwable
     */
    public function cancelUser(UserService $service)
    {
        $user_id = $this->getAuthId();
        $res = $service->cancelUser($user_id);
        $this->retSuccess($res);
    }




    /**修改密码
     * @param EditPasswordRequest $request
     * @param UserService $Service
     */
    public function editPassword(EditPasswordRequest $request, UserService $Service)
    {
        $user_id = $this->getAuthId();
        $password = $request->password();
        $password_confirmation = $request->password_confirmation();
        $old_password = $request->old_password();
        $info = $Service->editPassword($user_id, $password, $password_confirmation, $old_password);
        $this->retSuccess($info);
    }


    /** 编辑个人信息
     * @param UserService $Service
     */
    public function editUserInfo(EditUserInfoRequest $request, UserService $Service)
    {
        $user_id = $this->getAuthId();
        $params = $request->all();
        $info = $Service->editUserInfo($user_id, $params);
        $this->retSuccess($info);
    }




    /**忘记登录密码
     * @param UserForgetLoginPasswordRequest $request
     * @param UserService $Service
     */
    public function forgetLoginPassword(UserForgetLoginPasswordRequest $request, UserService $Service)
    {
        $password = $request->password();
        $password_confirmation = $request->password_confirmation();
        $code = $request->code();
        $phone = $request->phone();
        $res = $Service->forgetLoginPassword($phone, $code, $password, $password_confirmation);
        $this->retSuccess($res);
    }


    /** 获取个人信息
     * @param UserService $Service
     */
    public function getUserInfo(UserService $Service)
    {
        $user_id = $this->getAuthId();
        $res = $Service->getUserInfo($user_id);
        $this->retSuccess($res);
    }







    /**
     * 上传头像
     * @param AvatarRequest $request
     * @param UserService $Service
     * @return void
     */
    public function uploadAvatar(AvatarRequest $request, UserService $Service)
    {
        $user_id = $this->getAuthId();
        $avatar = $request->avatar();
        $res = $Service->uploadAvatar($user_id, $avatar);
        $this->retSuccess($res);
    }





    public function getUserDetails(UserService $Service)
    {
        $user_id = $this->getAuthId();
        $res = $Service->getUserDetails($user_id);
        $this->retSuccess($res);
    }

    public function myMtLog(Request $request, UserService $Service)
    {
        $user_id = $this->getAuthId();
        $page = $request->input('page', 1);
        $size = $request->input('size', 10);
        $res = $Service->myMtLog($user_id, $page, $size);
        $this->retSuccess($res);
    }

    public function myAtLog(Request $request, UserService $Service)
    {
        $user_id = $this->getAuthId();
        $role_type = 0;//0-导师；1-店铺；
        $page = $request->input('page', 1);
        $size = $request->input('size', 10);
        $res = $Service->myAtLog($user_id, $role_type, $page, $size);
        $this->retSuccess($res);
    }




}
